package com.lancoo.ccas52.redis;


import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.lancoo.ccas52.entity.TeachingClassStudent;
import com.lancoo.ccas52.pojo.common.StudentCourse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author： Lining
 * @date： 2021/8/16 16:22
 * @description： redis发送订阅模式生产者（性能较生产消费模式好）
 * @modifiedBy：
 * @version: 1.0
 */
@Component
@Slf4j
public class RedisMQPublisher {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    public void studentAddPreCourse(StudentCourse preSelectStudent) {
        redisTemplate.convertAndSend("student_add_pre_course", preSelectStudent);
        log.info("消息={}发送成功", preSelectStudent);
    }

    public void studentDropPreCourse(String message) {
        redisTemplate.convertAndSend("student_drop_pre_course", message);
        log.info("消息={}发送成功", message);
    }

    public void studentAddFormalCourse(TeachingClassStudent teachingClassStudent) {
        redisTemplate.convertAndSend("student_add_formal_course", teachingClassStudent);
        log.info("学生添加消息={}发送成功", teachingClassStudent);
    }

    public void studentDropFormalCourse(TeachingClassStudent teachingClassStudent) {
        redisTemplate.convertAndSend("student_drop_formal_course", teachingClassStudent);
        log.info("学生退选消息={}发送成功", teachingClassStudent);
    }
}

